package com.ehome.poct.core.dao.mybatis;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ehome.core.util.BeanConvertUtil;
import com.ehome.mybatisplus.support.AbstractCrudRepository;
import com.ehome.poct.core.api.dto.CheckStripQry;
import com.ehome.poct.core.api.dto.check.gold.TestConfPoctStripTypeDTO;
import com.ehome.poct.core.dao.entity.check.TestConfPoctStripTypeDO;
import com.ehome.poct.core.dao.mybatis.mapper.TestConfPoctStripTypeMapper;
import com.ehome.poct.core.repository.TestConfPoctStripTypeRepository;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 金标仪检测试纸类型配置RepositoryImpl
 *
 * @author muqiu
 * @Date 2022-03-19 16:51
 */
@Repository
@AllArgsConstructor
public class TestConfPoctStripTypeRepositoryImpl extends AbstractCrudRepository<TestConfPoctStripTypeDO, TestConfPoctStripTypeDTO> implements TestConfPoctStripTypeRepository {

    private final TestConfPoctStripTypeMapper mapper;
    @Override
    public List<TestConfPoctStripTypeDTO> selectWithoutUnion() {
        final var list = mapper.selectList(Wrappers.<TestConfPoctStripTypeDO>lambdaQuery()
                .notIn(TestConfPoctStripTypeDO::getTypeCode, List.of(0, 121)).orderByAsc(TestConfPoctStripTypeDO::getTypeCode));
        return BeanConvertUtil.convertBeanList(list, TestConfPoctStripTypeDTO.class);
    }
    @Override
    public List<TestConfPoctStripTypeDTO> selectWithoutUnion( CheckStripQry qry) {
        final var list = mapper.selectList(Wrappers.<TestConfPoctStripTypeDO>lambdaQuery()
                .eq(qry.getCheckType()!=null,TestConfPoctStripTypeDO::getTypeCode,qry.getCheckType())
                .eq(qry.getShowOriginPrice()!=null,TestConfPoctStripTypeDO::getShowOriginPrice,qry.getShowOriginPrice())
                .ge(qry.getStartTime()!=null,TestConfPoctStripTypeDO::getUpdateTime,qry.getStartTime())
                .le(qry.getEndTime()!=null,TestConfPoctStripTypeDO::getUpdateTime,qry.getEndTime())
                .notIn(TestConfPoctStripTypeDO::getTypeCode, List.of(0,50,51)).orderByAsc(TestConfPoctStripTypeDO::getTypeCode));
        return BeanConvertUtil.convertBeanList(list, TestConfPoctStripTypeDTO.class);
    }
}
